﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace RCREEE.Web
{
    public partial class AdjustSpecificYear : System.Web.UI.Page
    {
        RCREEE.Library.Entities.AdjustSpecificYear _adjust = new Library.Entities.AdjustSpecificYear();

        protected void Page_Load(object sender, EventArgs e)
        {
            BindEnergyConsumptionGrid();
            BindStrategicObjectivesGrid();

        }

        protected void gvEnergyConsumption_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string columnName = gvEnergyConsumption.Rows[e.RowIndex].Cells[0].Text;

            if (columnName != "")
            {
                _adjust.RemoveEnergyConsumptionColumn(columnName);
                BindEnergyConsumptionGrid();
            }

        }

        private void BindEnergyConsumptionGrid()
        {

            DataTable dtEnergyYears = _adjust.GetEnergyConsumptionColumns();
            if (dtEnergyYears != null)
                dtEnergyYears.Columns[0].ColumnName = "Year";
            gvEnergyConsumption.DataSource = dtEnergyYears;
            gvEnergyConsumption.DataBind();

        }

        private void BindStrategicObjectivesGrid()
        {

            DataTable dtStrategicObjectives = _adjust.GetStrategicObjectivesColumns();
            if (dtStrategicObjectives != null)
                dtStrategicObjectives.Columns[0].ColumnName = "Year";
            gvStrategicObjectives.DataSource = dtStrategicObjectives;
            gvStrategicObjectives.DataBind();

        }

        protected void gvStrategicObjectives_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string columnName = gvStrategicObjectives.Rows[e.RowIndex].Cells[0].Text;

            if (columnName != "")
            {
                _adjust.RemoveStrategicObjectiveColumn(columnName);
                BindStrategicObjectivesGrid();
            }
        }

        protected void btnAddEnergyYear_Click(object sender, EventArgs e)
        {
            if (txtNewEnergyYear.Text != "")
            {
                _adjust.AddEnergyConsumptionColumn(txtNewEnergyYear.Text);
                BindEnergyConsumptionGrid();
            }
        }

        protected void btnAddNewStrategicYear_Click(object sender, EventArgs e)
        {
            if (txtNewStrategicYear.Text != "")
            {
                _adjust.AddStrategicObjectiveColumn(txtNewStrategicYear.Text);
                BindStrategicObjectivesGrid();
            }
        }

    }
}